package com.gavin.security;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Base64 {
	private static BASE64Encoder encoder = new BASE64Encoder();
	private static BASE64Decoder decoder = new BASE64Decoder();

	public static String encode(byte[] bysData) {
		String strEncoded = null;
		synchronized (encoder) {
			strEncoded = encoder.encode(bysData);
		}
		strEncoded = strEncoded.replaceAll("\r\n", "");

		return strEncoded;
	}

	public static byte[] decode(String strData) {
		try {
			synchronized (decoder) {
				return decoder.decodeBuffer(strData);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
